package com.bootdo.clouddo.domain.user;

import com.bootdo.clouddo.core.security.XbGrantedAuthority;
import com.bootdo.clouddo.domain.user.vo.QaUsersVo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.springframework.beans.BeanUtils;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Transient;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;

public class QaUsers implements UserDetails {
	
	private static final long serialVersionUID = -6427892321481198228L;
	
	public static final String LOGIN_WAY_SMS = "1";//短信登陆
	public static final String LOGIN_WAY_PWD = "2";//密码登陆
	
	public static final String LOGIN_WAY_WXCODE = "3"; //微信code登录

    public static final String LOGIN_WAY_WXOPENID = "4"; //微信openid登录
	
	@Transient
	private String currentLoginWay;

    @Id
    @Column(name="UID",length=11, unique=true)
    @GeneratedValue(generator="JDBC")
    private Long uid;

   private String wxOpenid;
    
    private String wxUnionid;

    private String userName;

    private String email;

    private String mobile;

    @JsonIgnore
    private String password;
    @JsonIgnore
    private String salt;

    private String avatarFile;

    private String sex;

    private String birthday;

    private String province;
    //private String provinceCode;

    private String city;
    //private String cityCode;

    private Date regTime;

    private String regIp;

    //private Integer inviteCount;

    //private Integer invitationAvailable;

    private Integer groupId;

    private Boolean forbidden;

    private String nickname;

    private Double totalIntegral;

    private Double accountIntegral;

    private Double frozenIntegral;

    private Double exp;

    @Transient
    @JsonIgnore
    private Double rawExp;

    private Boolean vip;

    private Integer signInDays = 0;

    @Transient
    private String signInDaysOverPrec;

    private Integer commentAgreeCount;

    @Transient
    private String level;

    @Transient
    private Long levelId;
    
    @Transient
    private List<XbGrantedAuthority> authorities = new ArrayList<XbGrantedAuthority>();
    
    @Transient
    private String wxSessionKey;
	
	@JsonIgnoreProperties
	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		authorities.add(new XbGrantedAuthority("ROLE_GLOBAL"));
		return authorities;
	}

    public Long getUid() {
        return uid;
    }

    public void setUid(Long uid) {
        this.uid = uid;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getSalt() {
        return salt;
    }

    public void setSalt(String salt) {
        this.salt = salt;
    }

    public String getAvatarFile() {
        return avatarFile;
    }

    public void setAvatarFile(String avatarFile) {
        this.avatarFile = avatarFile;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getBirthday() {
        return birthday;
    }

    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public Date getRegTime() {
        return regTime;
    }

    public void setRegTime(Date regTime) {
        this.regTime = regTime;
    }

    public String getRegIp() {
        return regIp;
    }

    public void setRegIp(String regIp) {
        this.regIp = regIp;
    }

    public Integer getGroupId() {
        return groupId;
    }

    public void setGroupId(Integer groupId) {
        this.groupId = groupId;
    }


    public Boolean getForbidden() {
        return forbidden;
    }

    public void setForbidden(Boolean forbidden) {
        this.forbidden = forbidden;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

	@Override
	public String getPassword() {
		return this.password;
	}
	@Override
	public String getUsername() {
		return this.userName;
	}
	@Override
	public boolean isAccountNonExpired() {
		return true;
	}
	@Override
	public boolean isAccountNonLocked() {
		return true;
	}
	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}
	@Override
	public boolean isEnabled() {
		return true;
	}

	public String getCurrentLoginWay() {
		return currentLoginWay;
	}

	public void setCurrentLoginWay(String currentLoginWay) {
		this.currentLoginWay = currentLoginWay;
	}

	public String getWxSessionKey() {
		return wxSessionKey;
	}

	public void setWxSessionKey(String wxSessionKey) {
		this.wxSessionKey = wxSessionKey;
	}

	public String getWxOpenid() {
		return wxOpenid;
	}

	public void setWxOpenid(String wxOpenid) {
		this.wxOpenid = wxOpenid;
	}

	public String getWxUnionid() {
		return wxUnionid;
	}

	public void setWxUnionid(String wxUnionid) {
		this.wxUnionid = wxUnionid;
	}

    public QaUsers() {
    }

    public QaUsers(Long uid) {
        this.uid = uid;
    }

    public Double getTotalIntegral() {
        return totalIntegral;
    }

    public void setTotalIntegral(Double totalIntegral) {
        this.totalIntegral = totalIntegral;
    }

    public Double getAccountIntegral() {
        return accountIntegral;
    }

    public void setAccountIntegral(Double accountIntegral) {
        this.accountIntegral = accountIntegral;
    }

    public Double getFrozenIntegral() {
        return frozenIntegral;
    }

    public void setFrozenIntegral(Double frozenIntegral) {
        this.frozenIntegral = frozenIntegral;
    }

    public Double getExp() {
        return exp;
    }

    public void setExp(Double exp) {
        this.exp = exp;
    }


    public Boolean getVip() {
        return vip;
    }

    public void setVip(Boolean vip) {
        this.vip = vip;
    }

    public String getLevel() {
        return level;
    }

    public void setLevel(String level) {
        this.level = level;
    }

    public Integer getSignInDays() {
        return signInDays;
    }

    public void setSignInDays(Integer signInDays) {
        this.signInDays = signInDays;
    }

    public Double getRawExp() {
        return rawExp;
    }

    public void setRawExp(Double rawExp) {
        this.rawExp = rawExp;
    }

    public Long getLevelId() {
        return levelId;
    }

    public void setLevelId(Long levelId) {
        this.levelId = levelId;
    }

    public Integer getCommentAgreeCount() {
        return commentAgreeCount;
    }

    public void setCommentAgreeCount(Integer commentAgreeCount) {
        this.commentAgreeCount = commentAgreeCount;
    }

    public String getSignInDaysOverPrec() {
        return signInDaysOverPrec;
    }

    public void setSignInDaysOverPrec(String signInDaysOverPrec) {
        this.signInDaysOverPrec = signInDaysOverPrec;
    }

    public QaUsersVo toVo(){
        QaUsersVo userVo = new QaUsersVo();
        BeanUtils.copyProperties(this, userVo);
        return userVo;
    }
}